package com.ai.aicontact.common.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ai.aicontact.common.cache.AppCacheManager;
import com.ai.aicontact.common.constant.GlobalConstant;
import com.ai.aicontact.common.entity.SysStaticData;
import com.ai.aicontact.common.service.SysStaticDataService;
import com.ai.aicontact.core.dao.BaseDaoI;

@Service("sysStaticDataServiceImpl")
public class SysStaticDataServiceImpl implements SysStaticDataService {
	private AppCacheManager appCacheManager = AppCacheManager.getInstance();
	private Map m_static_data_cache_by_code_type = null;

	@Autowired
	private BaseDaoI<SysStaticData> bsStaticDataDao;

	public SysStaticDataServiceImpl() {
		if (m_static_data_cache_by_code_type == null) {
			m_static_data_cache_by_code_type = appCacheManager.getMap(GlobalConstant.STATIC_DATA_CACHE_BY_CODE_TYPE);
		} 
	}

	public List<SysStaticData> getStaticDataByCodyType(String codeType) throws Exception {
		if (m_static_data_cache_by_code_type.containsKey(codeType)) {
			return (List<SysStaticData>) m_static_data_cache_by_code_type.get(codeType);
		} else {
			String hql = "from SysStaticData where state = 'U' and codeType =:codeType";
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("codeType", codeType);
			List<SysStaticData> list = bsStaticDataDao.find(hql, params);
			m_static_data_cache_by_code_type.put(codeType, list);
			return list;
		}
	}
}
